#include "common.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>

int main()
{
	int sock_fd = socket(AF_INET, SOCK_STREAM, 0);
	if(sock_fd < 0)
		err_sys("socket error\n");

	struct sockaddr_in dest_addr;
	dest_addr.sin_family = AF_INET;
	dest_addr.sin_port = htons(9999);
	inet_pton(AF_INET, "127.0.0.1", &dest_addr.sin_addr);

	int ret = connect(sock_fd, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
	if(ret != 0)
		err_sys("connect error\n");

	char send_buf[1024] = {0};
	char recv_buf[1024] = {0};

	while(1)
	{
		printf("send : ");
		fgets(send_buf, 1024, stdin);
		send(sock_fd, send_buf, strlen(send_buf), 0);
		
		while(recv(sock_fd, recv_buf, 1024, 0) > 0)
		{
			printf("Time : %s\n", recv_buf);
			break;
		}
	}

	//recv(sock_fd, recv_buf, sizeof(recv_buf), 0);
	//printf("Time : %s\n", recv_buf);

	close(sock_fd);
	return 0;
}
